package com.tjmc.recruit.user.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.tjmc.recruit.user.entity.PersonalAnnexResumeInfoEntity;
import com.tjmc.recruit.user.service.PersonalAnnexResumeInfoService;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 个人附件简历表
 *
 * @author recruit
 * @date 2024-11-11 17:20:45
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/personalAnnexResumeInfo" )
@Tag(description = "personalAnnexResumeInfo" , name = "个人附件简历表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PersonalAnnexResumeInfoController {

    private final  PersonalAnnexResumeInfoService personalAnnexResumeInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param personalAnnexResumeInfo 个人附件简历表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getPersonalAnnexResumeInfoPage(@ParameterObject Page page, @ParameterObject PersonalAnnexResumeInfoEntity personalAnnexResumeInfo) {
        LambdaQueryWrapper<PersonalAnnexResumeInfoEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(personalAnnexResumeInfoService.page(page, wrapper));
    }


    /**
     * 通过条件查询个人附件简历表
     * @param personalAnnexResumeInfo 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject PersonalAnnexResumeInfoEntity personalAnnexResumeInfo) {
        return R.ok(personalAnnexResumeInfoService.list(Wrappers.query(personalAnnexResumeInfo)));
    }

    /**
     * 新增个人附件简历表
     * @param personalAnnexResumeInfo 个人附件简历表
     * @return R
     */
    @Operation(summary = "新增个人附件简历表" , description = "新增个人附件简历表" )
    @SysLog("新增个人附件简历表" )
    @PostMapping
    public R save(@RequestBody PersonalAnnexResumeInfoEntity personalAnnexResumeInfo) {
        boolean save = personalAnnexResumeInfoService.save(personalAnnexResumeInfo);
        if (save){
            return R.ok(personalAnnexResumeInfo);
        }
        return R.failed("新增失败");
    }

    /**
     * 修改个人附件简历表
     * @param personalAnnexResumeInfo 个人附件简历表
     * @return R
     */
    @Operation(summary = "修改个人附件简历表" , description = "修改个人附件简历表" )
    @SysLog("修改个人附件简历表" )
    @PutMapping
    public R updateById(@RequestBody PersonalAnnexResumeInfoEntity personalAnnexResumeInfo) {
        return R.ok(personalAnnexResumeInfoService.updateById(personalAnnexResumeInfo));
    }

    /**
     * 通过id删除个人附件简历表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除个人附件简历表" , description = "通过id删除个人附件简历表" )
    @SysLog("通过id删除个人附件简历表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(personalAnnexResumeInfoService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param personalAnnexResumeInfo 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<PersonalAnnexResumeInfoEntity> exportExcel(PersonalAnnexResumeInfoEntity personalAnnexResumeInfo,Long[] ids) {
        return personalAnnexResumeInfoService.list(Wrappers.lambdaQuery(personalAnnexResumeInfo).in(ArrayUtil.isNotEmpty(ids), PersonalAnnexResumeInfoEntity::getId, ids));
    }

    /**
     * 导入excel 表
     * @param personalAnnexResumeInfoList 对象实体列表
     * @param bindingResult 错误信息列表
     * @return ok fail
     */
    @PostMapping("/import")
    public R importExcel(@RequestExcel List<PersonalAnnexResumeInfoEntity> personalAnnexResumeInfoList, BindingResult bindingResult) {
        return R.ok(personalAnnexResumeInfoService.saveBatch(personalAnnexResumeInfoList));
    }
}
